package com.zc.wxPay.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.logging.SimpleFormatter;


/**
 * @Author gaojikun
 * @Description 随机数生成
 */
public class RandomStringGenerator {

    /**
     * 获取一定长度的随机字符串
     *
     * @param length 指定字符串长度
     * @return 一定长度的字符串
     */
    public static String getRandomStringByLength(int length) {
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat ("yyyyMMddHHmmssSSS");
        String base = "0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        sb.append(simpleDateFormat.format(new Date()));
        for (int i = 0; i < length-17; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }

}
